import fs from "fs";

class IdGenerator {
  private static cur = 0;
  private location = "ids"
  constructor() {
    if (!fs.existsSync(this.location)) {
      this.write(IdGenerator.cur)
    }
    this.read()
  }
  public gen() {
    IdGenerator.cur++;
    this.write(IdGenerator.cur)
    return IdGenerator.cur;
  }
  private read() {
    IdGenerator.cur = +fs.readFileSync(this.location).toString()
  }
  private write(data: number) {
    fs.writeFileSync(this.location, data + "")
  }
}

export const idGen = new IdGenerator()

